import { Post,Controller,Get, HttpCode,Body,Param,HttpStatus, Query } from '@nestjs/common';
import { AuthService } from '../curd/auth.service';
import { User } from '../models/user';
import { LoginOutputDto } from '../schames/login.dto';
import { LoginInputDto } from '../schames/auth.dto';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';

@ApiTags('认证模块')
@Controller('auth')
export class AuthController {
  constructor(private authService: AuthService) {}
  
  @HttpCode(HttpStatus.OK)
  @Get('userInfo/:id')
  @ApiOperation({ summary: '获取用户信息' })
  @ApiResponse({ status: 200, description: '返回用户信息'})
  async getAll(@Param('id') id: string): Promise<any> {
    console.log('22')
    return await this.authService.getUsers(id);
  }

  @Get('baseInfo')
  @ApiOperation({ summary: 'Query获取用户信息' })
  @ApiResponse({ status: 200, description: '返回用户信息' })
  async getUser(@Query('id') id: string): Promise<any> {
    console.log('22')
    return await this.authService.getUsers(id);
  }

  @Post('login')
  @ApiOperation({ summary: '用户登录' })
  @ApiResponse({ status: 200, description: '返回登录成功信息', type: LoginOutputDto })
  async login(@Body() loginDto: LoginInputDto): Promise<LoginOutputDto> {
    return this.authService.login(loginDto.username, loginDto.password);
  }

  @Post('register')
  @ApiOperation({ summary: '用户注册' })
  @ApiResponse({ status: 200, description: '返回注册成功信息', type: LoginOutputDto })
  async register(@Body() body: LoginInputDto): Promise<any> {
    return await this.authService.register(body.username, body.password);
  }
}